package ctrutil

import (
    "strings"
    "fmt"
)

const (
    AccessTcpPort8888 = "8888"
    AccessRpcPort8889 = "8889"

    AccessTcpPort9998 = "9998"
    AccessRpcPort9999 = "9999"
)

func GetRpcIDForAccessSrv(tcpAddress string) (string, error) {
    tmp := strings.TrimSpace(tcpAddress)

    elems := strings.Split(tmp, ":")
    if len(elems) != 2 {
        return "", fmt.Errorf("input tcp address is error")
    }

    var rpcId string
    domain := elems[0]
    port := elems[1]
    if port == AccessTcpPort8888 {
        rpcId = fmt.Sprintf("%s:%s", domain, AccessRpcPort8889)
    } else if port == AccessTcpPort9998 {
        rpcId = fmt.Sprintf("%s:%s", domain, AccessRpcPort9999)
    } else {
        return "", fmt.Errorf("the tcp port(%s) no set", port)
    }

    return rpcId, nil
}